
cc.Class({
    extends: cc.Component,

    properties: {
        launcher: require('SkillLauncher'),
        bosses: [cc.Node],
        launcherNode: cc.Node,
        planeNode: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.n_fireTime = 0
        this.n_bossId = 1;
        this.n_index = 0;
        SoundMgr.playMusic('./Audio/bgm_main')

    },

    start() {
    },

    closePanel() {
        this.node.active = false;
    },

    setPlaneId(id) {
        this.n_index = 0;
        this.clearBullet();
        this.launcher.setSkillParentNode(this.launcherNode, true);
        this.n_bossId = id.split('-');
        // for (var i in this.bosses) {
        //     this.bosses[i].active = false;
        // }
        // let index = 0;
        // if (this.n_bossId[0] == 'boss') {
        //     index = this.n_bossId[1] - 1;
        // } else {
        //     index = 3 + parseInt(this.n_bossId[1]) - 1;
        // }
        // this.bosses[index].active = true;
        this.level = 4
    },
    clearBullet() {
        this.launcherNode.removeAllChildren();
    },
    createBoss(){
        let name = '';
        if (this.n_bossId[0] == 'boss') {
            name = 'boss-' + this.n_bossId[1];
        } else {
            name = 'sBoss-' + this.n_bossId[1];
        }
        var option = global.DataConfig.monster[name];
        cc.loader.loadRes('BossHandBook/boss/' + option.prefab+'HandBook', function (e, r) {
            var prefab  = cc.instantiate(r);
            this.planeNode.addChild(prefab);
            prefab.getComponent('bossItem').setOptions(global.DataConfig.monster[name]);
        }.bind(this))
    },
    startFire() {
        this.launcher.reset();
        let skills = [];
        let name = '';
        if (this.n_bossId[0] == 'boss') {
            name = 'boss-' + this.n_bossId[1];
        } else {
            name = 'sBoss-' + this.n_bossId[1];
        }
        var option = global.DataConfig.monster[name];
        for (let item in option.status) {
            if (option.status[item].skill) skills.push(option.status[item].skill);
        };
        if (this.n_index >= skills.length) this.n_index = 0;
        this.launcher.addLauncher(skills[this.n_index][0])
        SoundMgr.playSound('Audio/Transform_hero_0', false, 5);
        this.n_index++;
    },

    Strengthen() {
        SoundMgr.playSound('Audio/button')
        global.EJMgr.pushUI('PlaneStrengthen/PlaneStrengthen')
    },
    update(dt) {
        // if(this.n_fireTime > 0){
        // this.n_fireTime -= dt;
        // if (this.n_fireTime < 0) {
        //     this.n_fireTime = 4;
        //     this.level = (this.level == 3 ? 4 : 3);
        //     this.startFire();
        // }
        // }
    },
});
